package org.jarraiders.musiclibrary.domain;

import java.io.Serializable;
import java.util.List;
import java.util.UUID;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

/**
 * @author AlteroStudio
 */
@Entity
@Table(name = "artists", schema = "public")
public class Artist implements Serializable {

	private static final long serialVersionUID = 6819013452269078919L;

	@Id
	@Column(name = "ar_id" )	
	@Type(type="pg-uuid")
	@Basic(optional = false)
	private UUID artistId;

	@Column(name = "ar_name")
	@Basic(optional = false)
	private String artistName;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "artist_id", fetch = FetchType.LAZY)
	private List<Album> albumsList;
	
	public Artist(){
		
	}

	public Artist(UUID uuid, String artistName){
		this.artistId=uuid;
		this.artistName=artistName;
	}
	public UUID getArtistId() {
		return artistId;
	}

	public void setArtistId(UUID artistId) {
		this.artistId = artistId;
	}

	public String getArtistName() {
		return artistName;
	}

	public void setArtistName(String artistName) {
		this.artistName = artistName;
	}

	public List<Album> getAlbumsList() {
		return albumsList;
	}

	public void setAlbumsList(List<Album> albumsList) {
		this.albumsList = albumsList;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((artistId == null) ? 0 : artistId.hashCode());
		result = prime * result
				+ ((artistName == null) ? 0 : artistName.hashCode());
		return result;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Artist [artistId=");
		builder.append(artistId);
		builder.append(", artistName=");
		builder.append(artistName);
		builder.append(", albumsList=");
		builder.append(albumsList);
		builder.append("]");
		return builder.toString();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Artist other = (Artist) obj;
		if (artistId == null) {
			if (other.artistId != null)
				return false;
		} else if (!artistId.equals(other.artistId))
			return false;
		if (artistName == null) {
			if (other.artistName != null)
				return false;
		} else if (!artistName.equals(other.artistName))
			return false;
		return true;
	}
}